//新好友申请通知
function newFriendApplyNotify(data){

    var temp = '<li id="new-friend-apply-'+data.senderId+'"><img class="list-name" src="">' +
        '<div class="list-text"><h2><span class="session-name">'+data.senderName+'</span>' +
        '<span class="time">待通过</span></h2>' +
        '<p><em id="send-status" class="iconn-35 hideList"></em>' +
        '<span class="session-text">'+data.extra+'</span></p></div></li>';
    $('#new-friend-ul').prepend(temp);
    $('#new-friend-apply-'+data.senderId).data(data);

}

//点击好友申请打开申请详情
function openFriendApplyDetail(node){
    applyInfo = $(node).data();
    console.log(applyInfo);
    contactId = applyInfo.senderId;
    $('#friend-apply-detail-name').html(applyInfo.senderName);
    $('#friend-apply-detail').siblings().hide();
    $('#friend-apply-detail').show();
}

/**
 * 点击好友打开详情
 */
function openFriendDetail(node){
    userId = $(node).attr('userId');
    contactId = userId;
    contactObject.getUserInfo(userId,function(userInfo){
        userInfo_ = JSON.parse(userInfo);
        $('#friend-detail-name').html(userInfo_.username);
        $('#friend-detail-avatar').attr('src',userInfo_.avatar);
        $('#friend-detail-id').html('<em>挖辣辣号</em>' + userInfo_.userId);
        $('#friend-detail').siblings().hide();
        $('#friend-detail').show();
    })
}

function examineFriend(node) {
    var status = $(node).attr('status');
    contactObject.examine(contactId,status,function(result){
        console.log('发送好友审核结果',result);
        if(result == 0){
            if(status == 0){
                $('#new-friend-apply-' + applyFriendId).find('.time').html('已通过');
            }else{
                $('#new-friend-apply-' + applyFriendId).find('.time').html('已拒绝');
            }
            $('#contact-no-record').siblings().hide();
            $('#contact-no-record').show();
        }
    })
}

/**
 * 刷新好友列表
 * @param list
 */
function refreshFriendList(list){
    console.log('好友列表更新',list);
    //好友是否存在
    for(var i = 0;i < list.length; i ++){
        var exist = $('#friend-' + list[i].userId);
        if(exist.length == 0){
            var temp = '<li id="friend-'+list[i].userId+'" userId="'+list[i].userId+'"><img class="list-name" src="'+list[i].avatar+'">' +
            '<div class="list-text"><h2 class="friend-name"><span class="session-name">'+list[i].username+'</span>' +
            '</h2></div></li>';
            $('#friend-ul').prepend(temp);
        }else{
            //todo 更新好友
        }
    }

}

function changeExamineResult(userId,status){

}